package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.data.CustAttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * @author zhoujiao
 * @create 2021-12-12-09:41
 */
public class GoSmartAddProdQuantityAttrHandler extends AbstractAttrHandler<KiteInst, CustAttrData> {
   @Autowired
    IQuerySceneInstService querySceneInstService;

    @Override
    public void def(KiteAttr attr, KiteInst inst, CustAttrData data) {
        //附加商品订购数量联动
        String sceneInstId = data.getSceneInstId();
        List<KiteProdInst> kiteProdInstList = querySceneInstService.listProdInsts(sceneInstId);
        for (KiteProdInst kiteProdInst : kiteProdInstList) {
            //根据主框架的订购数量 实现联动
            if("63249664".equals(kiteProdInst.getSpecId())){      //63249664框架主产品的prodId
                KiteAttr quantityKiteAttr = kiteProdInst.getAttr("200001696");
                String quantity = quantityKiteAttr.getValue();
                attr.setDefaultValue(quantity);
                break;
            }
        }
        super.def(attr, inst, data);
    }
}

